package com.apes.scm.stock.inventory.service;

import com.apes.framework.api.DomainService;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import com.apes.framework.plugin.event.Listener;
import com.apes.scm.stock.inventory.model.InventoryMark;
import com.apes.scm.stock.inventory.repository.InventoryMarkRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;

@Service("inventoryMarkService")
public class InventoryMarkService extends DomainService {

    @Autowired
    private EntityManager entityManager;

    @Autowired
    private InventoryMarkRepository inventoryMarkRepository;
    

    /**
     * 保存
     *
     * @param request
     * @return
     */
    @Listener(topic = "event:scm.inventoryMarkService.save")
    public InventoryMark save(SimpleRequest request) {
        InventoryMark inventoryMark = request.getO(InventoryMark.class);
        return inventoryMarkRepository.saveAndFlush(inventoryMark);
    }

    /**
     * 删除
     *
     * @param request
     * @return
     */
    @Listener(topic = "event:scm.inventoryMarkService.delete")
    public void deleteForEvent(SimpleRequest request) {
        String str = request.getS();
        String id= str.replace("\"", "");
        inventoryMarkRepository.deleteById(id);
    }
}
